package com.csy.property.controller.community;

import com.csy.commons.core.controller.BaseController;
import com.csy.commons.core.domain.BaseResponse;
import com.csy.commons.core.page.PageResult;
import com.csy.property.community.domain.AjFacility;
import com.csy.property.community.domain.vo.AjFacilityWhRecordVo;
import com.csy.property.community.service.IAjFacilityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 
 * @since 2025-01-23
 */
@RestController
@RequestMapping("/system/facility")
public class AjFacilityController extends BaseController {
    @Autowired
    IAjFacilityService ajFacilityService;

    @GetMapping("/list")
    public PageResult list(AjFacility ajFacility) {
        startPage();
        List<AjFacility> list = ajFacilityService.getFacilityList(ajFacility);
        return getData(list);
    }

    @GetMapping("/{facilityId}")
    public List<AjFacilityWhRecordVo> getFacilityWhRecords(@PathVariable("facilityId") Integer facilityId ) {

        List<AjFacilityWhRecordVo> list = ajFacilityService.getFacilityWhRecords(facilityId);

        return list;
    }

    @PostMapping
    public BaseResponse addFacility(@RequestBody AjFacility ajFacility){
        return toAjax(ajFacilityService.add(ajFacility));
    }
    @PostMapping("/addWH")
    public BaseResponse addWH(@RequestBody AjFacilityWhRecordVo recordVo){
        recordVo.setFacilityId(recordVo.getId());
        recordVo.setId(null);

        return toAjax(ajFacilityService.addWH(recordVo));
    }
    @PutMapping("/check")
    public BaseResponse checkFacility(@RequestBody AjFacility ajFacility){
        if ("待审核".equals(ajFacility.getStatus())){
            return BaseResponse.fail("审核被拒绝");
        }
        boolean b = ajFacilityService.updateById(ajFacility);
        return toAjax(b == true ? 1 : 0 );
    }






}
